/**
 * 
 */
package net.teamix;

import java.util.List;

import javax.faces.component.UIParameter;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import net.teamix.Utils.FacesUtil;

import org.w3c.dom.Element;

/**
 * @author "Svetoslav Batchovski"
 *
 */
public class TranslationElementsControllerBean {
	
	XMLService xmlService;
	
	String newMsgId;
		
	public List<TranslationElement> getTranslationElements (){
	      return getXmlService().getTranslationElements();
	}

	public XMLService getXmlService() {
		return xmlService;
	}

	public void setXmlService(XMLService xmlservice) {
		this.xmlService = xmlservice;
	}
	
	
	public void selectTranslationElement(ActionEvent event){
		 
		 getRequest().getSession().setAttribute("translationMsgId", FacesUtil.getActionAttribute(event, "transmsgId"));
		 
	}
	
	private HttpServletRequest getRequest() {
		return (HttpServletRequest) FacesContext.getCurrentInstance()
				.getExternalContext().getRequest();
	}

	public String getNewMsgId() {
		return newMsgId;
	}

	public void setNewMsgId(String newMsgId) {
		this.newMsgId = newMsgId;
	}
	
	public String addNewMsgId() {
		String outcome = "failure";
		try {
			getRequest().getSession().setAttribute("changed", "1");
			getXmlService().addNewMsgID(getNewMsgId());
			outcome = "success";
		} catch (Exception e) {
		}
		return outcome;
	}
	
	public void delMsgId(ActionEvent event){	
		getXmlService().delMsgId(FacesUtil.getActionAttribute(event, "transmsgId"));
	}
}
